<template>
  <div>
    <div id="page">
      <!-- 头部 -->
      <header>
        <span class="iconfont">&#xe6bc;</span>
        <h2>手机登入</h2>
        <p>
          <span class="iconfont">&#xf0112;</span>
          <span class="iconfont">&#xe71e;</span>
          <i></i>
        </p>
      </header>
      <main>
        <h1>
          <img src="../../assets/images/logo.jpg" alt="" />
        </h1>
        <p>
          <i>手机号</i
          ><input class="phone_number" type="text" v-model="user.phone" />
        </p>
        <p>
          <i>密&nbsp;&nbsp;&nbsp;&nbsp;码</i
          ><input class="code" type="password" v-model="user.password" />
        </p>
        <button class="enter" @click="login">登录</button>
        <span class="regitser"
          >还没有账号？ <router-link to="/register">去注册</router-link>
        </span>
      </main>
    </div>
  </div>
</template>

<script>
import { login } from "../../request/api";
import { mapActions, mapGetters } from "vuex";
export default {
  // beforeRouteEnter(to,from,next){
  // let token = sessionStorage.getItem("person")
  // if(token){
  //   next()
  // }else{
  //   next("/login")
  // }
  // },
  data() {
    return {
      user: {
        phone: "",
        password: "",
      },
    };
  },
  methods: {
    ...mapActions({
      asyncUser: "asyncChangeUser",
    }),
    login() {
      login(this.user).then((res) => {
        if (res.data.code == 200) {
          //出现登录成功的提示窗
          this.Toast.success(res.data.msg);
          //跳转到首页
          this.$router.push("/index/home");
          //在asyncUser中存储用户信息
          this.asyncUser(res.data.list);
        } else {
          this.Toast.fail(res.data.msg);
        }
      });
    },
  },
  computed: {
    ...mapGetters({
      User: "user",
    }),
  },
  mounted() {},
};
</script>

<style scoped>
.regitser {
  display: inline-block;
  padding: 0.2rem 0 0 0.5rem;
}
.regitser a {
  text-decoration: underline;
  color: #ff6040;
}
html,
body,
#page {
  height: 100%;
}
#page {
  max-width: 7.5rem;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
}
/*头部*/
header {
  height: 0.8rem;
  background: #ff6040;
  display: flex;
  color: #ffdfd8;
  padding: 0.3rem 0.12rem 0.12rem 0.33rem;
  align-items: center;
  margin-bottom: 0.2rem;
}
header h2 {
  font-size: 0.3rem;
  margin: 0 1.2rem 0 2.5rem;
}
header p {
  width: 1.72rem;
  height: 0.62rem;
  border: 1px solid #ff876c;
  border-radius: 0.31rem;
  line-height: 0.62rem;
  display: flex;
  justify-content: space-between;
  position: relative;
}
header p span {
  width: 0.86rem;
  text-align: center;
}
header p i {
  width: 1px;
  height: 0.37rem;
  background: #ff876c;
  position: absolute;
  left: 0.86rem;
  top: 0.12rem;
}
/*主体*/
main {
  flex: 1;
  overflow: auto;
  width: 95%;
  background: #fff;
  margin: 0 auto;
  padding: 4.87rem 0 1rem;
  margin-bottom: 0.87rem;
}
main h1 {
  width: 3.65rem;
  margin: 0 auto;
  margin-bottom: 0.4rem;
}
main h1 img {
  width: 100%;
  display: block;
}
main p {
  width: 6.1rem;
  height: 0.98rem;
  border-bottom: 1px solid #f7f7f7;
  margin: 0 auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
main p span {
  width: 1.6rem;
  height: 0.48rem;
  background: #cccccc;
  text-align: center;
  line-height: 0.48rem;
}
main p .phone_number {
  border: none;
  width: 5.25rem;
  height: 0.98rem;
  position: fixed;
  right: 0.23rem;
}
main p .code {
  border: none;
  height: 0.98rem;
  width: 3.4rem;
  position: fixed;
  right: 2.1rem;
}
main .enter {
  width: 6.1rem;
  height: 0.98rem;
  background: #cccccc;
  margin: 0 auto;
  display: block;
  line-height: 0.98rem;
  color: #fff;
  font-weight: bold;
  font-size: 0.3rem;
  text-align: center;
  margin-top: 0.4rem;
  border: none;
}
</style>